package com.lanou.eight;

import javafx.print.Collation;

import java.util.*;

/**
 * @author zyj
 * @date 2022年05月24日 16:26
 */
public class Test {
    public static void main(String[] args) {

        HashMap<Integer, String> map = setStations();

        map.forEach((k,v) ->{
            System.out.println(k + ":" + v);
        });
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入上车站：");
        String shangChe = null;
        while (!map.containsValue(shangChe = sc.next())){
            System.out.println("您输入的上车站：" + shangChe + "不存在，请重新输入上车站");
        }
        System.out.println("请输入到达站：");
        String daoDa = null;

        while (!map.containsValue(daoDa = sc.next())){
            System.out.println("您输入的上车站：" + daoDa + "不存在，请重新输入上车站");
        }

        int num = getStations(map,shangChe,daoDa);
        System.out.println("从" + shangChe + "到" + daoDa
                + "共经过" + num + "站,收费" + getPrice(num) + "元，大约需要"
                + (num*2) + "分钟");



    }

    private static int getPrice(int num) {
        if (num <= 3 ){
            return 3;
        }else if (num <= 5){
            return 4;
        }else {
            return (num-5)*2 + 4 <= 10?(num-5)*2 + 4:10;
        }
    }

    private static int getStations(Map<Integer,String> map,String shangChe,String daoDa) {
        int num1 = getNum(map,shangChe);
        int num2 = getNum(map,daoDa);
        return Math.abs(num1-num2);
    }

    private static int getNum(Map<Integer, String> map, String station) {
       Set<Integer> set =  map.keySet();
        for (int i:set) {
            if (Objects.equals(map.get(i),station)){
                return i;
            }
        }
        return -1;
    }

    private static HashMap<Integer, String> setStations() {
        HashMap<Integer,String> map = new HashMap();

        map.put(1,"鱼化寨");
        map.put(2,"丈八北路");
        map.put(3,"延平门");
        map.put(4,"科技路");
        map.put(5,"太白南路");
        map.put(6,"吉祥村");
        map.put(7,"小寨");
        map.put(8,"大雁塔");
        map.put(9,"北池头");
        map.put(10,"青龙寺");
        map.put(11,"延兴门");
        map.put(12,"咸宁路");
        map.put(13,"长乐公园");
        map.put(14,"通化门");
        map.put(15,"胡家庙");
        map.put(16,"石家街");
        map.put(17,"辛家庙");
        map.put(18,"广泰门");
        map.put(19,"桃花潭");
        map.put(20,"浐灞中心");
        map.put(21,"香湖湾");
        map.put(22,"务庄");
        map.put(22,"国际港务区");
        return map;
    }
}
